/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.zx.topic.conversation.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.zx.topic.conversation.entity.TtopicOfConversation;
import com.jeesite.modules.zx.topic.conversation.service.TtopicOfConversationService;

/**
 * 社群管理Controller
 * @author zpp
 * @version 2020-02-03
 */
@Controller
@RequestMapping(value = "${adminPath}/zx/topic/conversation/ttopicOfConversation")
public class TtopicOfConversationController extends BaseController {

	@Autowired
	private TtopicOfConversationService ttopicOfConversationService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public TtopicOfConversation get(String id, boolean isNewRecord) {
		return ttopicOfConversationService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("zx:topic:conversation:ttopicOfConversation:view")
	@RequestMapping(value = {"list", ""})
	public String list(TtopicOfConversation ttopicOfConversation, Model model) {
		model.addAttribute("ttopicOfConversation", ttopicOfConversation);
		return "modules/zx/topic/conversation/ttopicOfConversationList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("zx:topic:conversation:ttopicOfConversation:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<TtopicOfConversation> listData(TtopicOfConversation ttopicOfConversation, HttpServletRequest request, HttpServletResponse response) {
		ttopicOfConversation.setPage(new Page<>(request, response));
		Page<TtopicOfConversation> page = ttopicOfConversationService.findPage(ttopicOfConversation);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("zx:topic:conversation:ttopicOfConversation:view")
	@RequestMapping(value = "form")
	public String form(TtopicOfConversation ttopicOfConversation, Model model) {
		model.addAttribute("ttopicOfConversation", ttopicOfConversation);
		return "modules/zx/topic/conversation/ttopicOfConversationForm";
	}

	/**
	 * 保存社群管理
	 */
	@RequiresPermissions("zx:topic:conversation:ttopicOfConversation:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated TtopicOfConversation ttopicOfConversation) {
		ttopicOfConversationService.save(ttopicOfConversation);
		return renderResult(Global.TRUE, text("保存社群管理成功！"));
	}
	
	/**
	 * 停用社群管理
	 */
	@RequiresPermissions("zx:topic:conversation:ttopicOfConversation:edit")
	@RequestMapping(value = "disable")
	@ResponseBody
	public String disable(TtopicOfConversation ttopicOfConversation) {
		ttopicOfConversation.setStatus(TtopicOfConversation.STATUS_DISABLE);
		ttopicOfConversationService.updateStatus(ttopicOfConversation);
		return renderResult(Global.TRUE, text("停用社群管理成功"));
	}
	
	/**
	 * 启用社群管理
	 */
	@RequiresPermissions("zx:topic:conversation:ttopicOfConversation:edit")
	@RequestMapping(value = "enable")
	@ResponseBody
	public String enable(TtopicOfConversation ttopicOfConversation) {
		ttopicOfConversation.setStatus(TtopicOfConversation.STATUS_NORMAL);
		ttopicOfConversationService.updateStatus(ttopicOfConversation);
		return renderResult(Global.TRUE, text("启用社群管理成功"));
	}
	
	/**
	 * 删除社群管理
	 */
	@RequiresPermissions("zx:topic:conversation:ttopicOfConversation:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(TtopicOfConversation ttopicOfConversation) {
		ttopicOfConversationService.delete(ttopicOfConversation);
		return renderResult(Global.TRUE, text("删除社群管理成功！"));
	}
	
}